﻿using System;
using System.Threading.Tasks;
using API.Interfaces;
using Framework.Business;
using Framework.Extensions;
using RealDataReceiver.Business;
using RealDataReceiver.Entities;

namespace RealDataReceiver.Service
{
    public class MessageConsumeService:RestServiceBase<MessageConsumeRequest>
    {
        public override object OnPost(MessageConsumeRequest request)
        {
            var response = new MessageConsumeResponse();
            var ctx = new ServiceContextBase<MessageConsumeRequest, MessageConsumeResponse>(request, response);
            try
            {
                //Task.Run(()=>RealDataReceiveBusiness.ConsumeMessage(ctx));
                RealDataReceiveBusiness.ConsumeMessage(ctx);
                ctx.Response.Succeeded = true;
            }
            catch (Exception e)
            {
                response.CaptureException(e);
            }

            return response;
        }
    }
}
